﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LongGi.TingkatKebocoranModule.CommModel
{
    public static  class ExportFileCommon
    {

        public static void ExportFile<T>(string fileName,List<T> data)
        {
            string folderPath = @"D:\ExPortData";

            try
            {
                // 检查文件夹是否存在
                if (!Directory.Exists(folderPath))
                {
                    // 不存在则创建文件夹
                    Directory.CreateDirectory(folderPath);
                    Console.WriteLine($"文件夹已创建：{folderPath}");
                }
                else
                {
                    Console.WriteLine("文件夹已存在");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"操作失败：{ex.Message}");
            }

            DataTable dt = data.ToDataTable();
            string s = fileName + DateTime.Now.ToString("yyyy-MM-dd HH-mm");
            // 导出为 xlsx 文件
            ExcelExporter.ExportToExcel(dt, @"D:\ExPortData\" + s + ".xlsx");
        }


    }
}
